package main

import (
	"io"
	"log"
	"net/http"
	"os/exec"
)

func reLaunch() {
	cmd := exec.Command("sh", "deploy.sh")
	err := cmd.Start()
	if err != nil {
		log.Fatalln("reLaunch: ", err)
	}
	err = cmd.Wait()
}

func main() {
	http.HandleFunc("/deploy", func(w http.ResponseWriter, r *http.Request) {
		io.WriteString(w, "<h1>deploy run...</h1>")
		reLaunch()
	})

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		io.WriteString(w, "<h1>go deploy index！</h1>")
	})

	http.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
		io.WriteString(w, "<h1>go deploy test!!!</h1>")
	})

	http.ListenAndServe(":8080", nil)
}
